﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Tradex.Market;

namespace Tradex.Trading {
    
    /// <summary>
    /// The Orderinfo object contains the basic (and thus most static) information about an order. This is
    /// the information entered by the order creation (what to buy or sell at which price), but does not
    /// contain dynamic update information. It can change, through, with order modifications - which some
    /// exchanges do for market orders (like the CME, which automatically transforms a market order to a
    /// prety distant limit order.
    /// </summary>
    public class OrderInfo {

        /// <summary>
        /// The main constructor of the OrderInfo.
        /// </summary>
        /// <param name="operation"></param>
        /// <param name="quantity"></param>
        /// <param name="type"></param>
        /// <param name="limit"></param>
        /// <param name="duration"></param>
        /// <param name="trigger"></param>
        public OrderInfo (
            OrderAction operation, int quantity, OrderType type, double limit, OrderDuration duration, Trigger trigger
        ) {
            Operation = operation;
            Quantity = quantity;
            OrderType = type;
            Limit = limit;
            Duration = duration;
            Trigger = trigger;
        }

        /// <summary>
        /// Constructor taking all values.
        /// </summary>
        /// <param name="account"></param>
        /// <param name="instrument"></param>
        /// <param name="operation"></param>
        /// <param name="quantity"></param>
        public OrderInfo (
            AccountKey account, InstrumentKey instrument,
            OrderAction operation, int quantity
        ) {
            Account = account;
            Instrument = instrument;

            Operation = operation;
            Quantity = quantity;
            OrderType = OrderType.Market;
            Limit = Double.NaN;
            Duration = OrderDuration.EndOfDay;
            Trigger = null;
        }

        /// <summary>
        /// Constructor taking all values.
        /// </summary>
        /// <param name="account"></param>
        /// <param name="instrument"></param>
        /// <param name="operation"></param>
        /// <param name="quantity"></param>
        /// <param name="limit"></param>
        public OrderInfo (
            AccountKey account, InstrumentKey instrument,
            OrderAction operation, int quantity, double limit
        ) {
            Account = account;
            Instrument = instrument;

            Operation = operation;
            Quantity = quantity;
            OrderType = OrderType.Limit;
            Limit = limit;
            Duration = OrderDuration.EndOfDay;
            Trigger = null;
        }

        /// <summary>
        /// This is the account for which the order is to be executed.
        /// </summary>
        public AccountKey Account { get; private set; }

        /// <summary>
        /// This is the instrument which the order handles.
        /// </summary>
        public InstrumentKey Instrument { get; private set; }

        /// <summary>
        /// This is the operation to perform with the order: Buy or Sell
        /// </summary>
        public OrderAction Operation { get; private set; }

        /// <summary>
        /// This is the quantity to handle.
        /// </summary>
        public int Quantity { get; private set; }

        /// <summary>
        /// Gets the OrderType of the order.
        /// </summary>
        public OrderType OrderType { get; private set; }

        /// <summary>
        /// This is the limit price to use. Double.NAN indicates this is not a number (no limit).
        /// </summary>
        public double Limit { get; private set; }

        /// <summary>
        /// This is the duration the order should be active.
        /// </summary>
        public OrderDuration Duration { get; private set; }

        /// <summary>
        /// This is the trigger for entering the order. This is used to generate Stop/MIT type
        /// of orders.
        /// </summary>
        public Trigger Trigger { get; private set; }

    }
}
